﻿#ifndef _HILOG_H__
#define _HILOG_H__

#define LOG_SOCK_PATH "/tmp/log.sock"
#define MAX_APP_LOG_LEN 1024
#define LOG_PORT 9800   //the log port
#define MAX_SOCKFD 10   //the max_num that the log service is able to connect

typedef struct
{
    long int occur_time;
    int level;
    int type;
    char source[16];
    char action[20];
    char description[MAX_APP_LOG_LEN];
}item_log;

class HiLogLevel
{
public:
    static const int Verbose = 0x01;
    static const int Info = 0x02;
    static const int Trace = 0x03;
    static const int Warn = 0x04;
    static const int Error = 0x05;
    static const int Disabled = 0x06;
};

class HiLogInterface
{
public:
    virtual void verbose(const char* tag, int context_id, const char* fmt, ...) = 0;
    virtual void info(const char* tag, int context_id, const char* fmt, ...) = 0;
    virtual void trace(const char* tag, int context_id, const char* fmt, ...) = 0;
    virtual void warn(const char* tag, int context_id, const char* fmt, ...) = 0;
    virtual void error(const char* tag, int context_id, const char* fmt, ...) = 0;
    virtual void log_set(const char *log_filename) = 0;
};

extern HiLogInterface* _hi_log;

#define hi_log_filename(msg) _hi_log->log_set(msg);
#define hi_verbose(msg, ...) _hi_log->verbose(__FUNCTION__,__LINE__, msg, ##__VA_ARGS__)
#define hi_info(msg, ...)    _hi_log->info(__FUNCTION__, __LINE__, msg, ##__VA_ARGS__)
#define hi_trace(msg, ...)   _hi_log->trace(__FUNCTION__, __LINE__, msg, ##__VA_ARGS__)
#define hi_warn(msg, ...)    _hi_log->warn(__FUNCTION__, __LINE__, msg, ##__VA_ARGS__)
#define hi_error(msg, ...)   _hi_log->error(__FUNCTION__, __LINE__, msg, ##__VA_ARGS__)
#define hi_debug(msg, ...)   _hi_log->info(__FUNCTION__, __LINE__, msg, ##__VA_ARGS__)

#endif // HILOG_H
